package arithmetic2.day07;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;

/*
    图的一条边
 */
public class Edge implements Comparable<Edge>{
    //当前边的权重
    public int weight;
    //当前边的起始节点
    public Node from;
    //当前边的结束节点
    public Node to;

    public Edge(int weight) {
        this.weight = weight;
    }

    public Edge(int weight, Node from, Node to) {
        this.weight = weight;
        this.from = from;
        this.to = to;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Edge edge = (Edge) o;
        return weight == edge.weight &&
                from.equals(edge.from) &&
                to.equals(edge.to);
    }

    @Override
    public int hashCode() {
        return Objects.hash(weight, from, to);
    }

    @Override
    public int compareTo(Edge o) {
        return this.weight-o.weight;
    }

    public static void main(String[] args) {
//        ArrayList<Edge> edges = new ArrayList<>();
//        edges.add(new Edge(10));
//        edges.add(new Edge(5));
//        edges.add(new Edge(1));
//        Collections.sort(edges);
//        for(Edge edge:edges){
//            System.out.println(edge.weight);
//        }

        Node node = new Node(1);
        Node node1 = new Node(1);
        System.out.println(node.equals(node1));
    }
}
